using System;
using System.Collections.Generic;
using axCommerce.Data.Interface;

namespace axCommerce.Data
{
	public partial class Product : IComparable<Product>, ISimpleData
	{
		public List<Photo> Photos { get; set; }

		public List<Comment> Comments { get; set; }

		public RatingCollection RatingInfo { get; private set; }

		private void FillPhotos()
		{
			if (ProductId.HasValue)
				Photos = Photo.GetAllPhotos(ProductId.Value);
		}

		private void FillRatingInfo()
		{
			if (ProductId.HasValue)
				RatingInfo = new RatingCollection(ProductId.Value, true);
		}

		private void FillComments()
		{
			if (ProductId.HasValue)
				Comments = Comment.GetAllComments(ProductId.Value);
		}

		public void Save()
		{
			CreatedDate = DateTime.Now;
			LastModifiedDate = DateTime.Now;
			IsDeleted = false;

			Insert();
		}

		public void UpdateInstance()
		{
			LastModifiedDate = DateTime.Now;

			Update();
		}

		public void MarkAsDeleted()
		{
			LastModifiedDate = DateTime.Now;
			IsDeleted = true;

			Update();
		}

		public int CompareTo(Product other)
		{
			return Name.CompareTo(other.Name);
		}
	}
}

